package ct.zxd.db;
import java.sql.*;
import java.util.*;

public class DBconn {
	final static String driver="com.mysql.jdbc.Driver";
//	final static String url="jdbc:mysql://42.194.187.218:3306/ordersys";
	final static String url="jdbc:mysql://127.0.0.1:3306/ordersys";

	final static String user="root";
	final static String password="gdgt#0320"; 
//	final static String password="root"; 	
//	final static String password="Zxd1982*";    // 谢威服务器mysql密码
	static{		
		try{
			Class.forName(driver);
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
  public static Connection getconn() throws SQLException{
	  Connection conn=null;
	  conn=DriverManager.getConnection(url,user,password);
	  return conn;
  }  
  
  public static void closeconn( Connection conn){	  
	  try {
		if(conn!=null && !conn.isClosed()){
			  conn.close();
		  }
	} catch (SQLException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
  }
  
  public static List<Map<String,Object>> getList(ResultSet rs) throws SQLException {
			if(rs==null) return null;
			List<Map<String,Object>> list=new ArrayList<Map<String,Object>>();
			ResultSetMetaData rmd= rs.getMetaData();
			int columNum=rmd.getColumnCount();
			while(rs.next()){//处理所有记录
				Map<String,Object> map= new HashMap<String,Object>();	
				for(int i=0;i<columNum;i++){//处理一行
					String columName=rmd.getColumnName(i+1);
					Object ob=rs.getObject(i+1);
					map.put(columName, ob);
			}
			list.add(map);
		}
		rs.close();
		return list;
	}

}
